package com.tdkj.service.shop.impl;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tdkj.dao.shop.IBeanShopRecommendationCustomDao;
import com.tdkj.model.shop.BeanShopRecommendationCustom;
import com.tdkj.model.shop.BeanShopRecommendationType;
import com.tdkj.service.BaseService;
import com.tdkj.service.shop.IBeanShopRecommendationCustomService;

@Component
public class BeanShopRecommendationCustomServiceImpl extends BaseService
		implements IBeanShopRecommendationCustomService {
	
	private IBeanShopRecommendationCustomDao beanShopRecommendationCustomDao;

	/**
	 * @param beanShopRecommendationCustomDao the beanShopRecommendationCustomDao to set
	 */
	@Resource
	public void setBeanShopRecommendationCustomDao(
			IBeanShopRecommendationCustomDao beanShopRecommendationCustomDao) {
		this.beanShopRecommendationCustomDao = beanShopRecommendationCustomDao;
	}

	@Override
	public BeanShopRecommendationCustom add(Long typeId,
			BigDecimal timeLimitQuantity, String timeLimitUnit, BigDecimal price, String unit,
			Long scoreLower, Integer goodNumber) {
		BeanShopRecommendationType type = beanShopRecommendationCustomDao.findById(typeId, BeanShopRecommendationType.class);
		
		BeanShopRecommendationCustom bean = new BeanShopRecommendationCustom();
		bean.setType(type);
		bean.setGoodNumber(goodNumber);
		bean.setPrice(price);
		bean.setUnit(unit);
		bean.setScoreLower(scoreLower);
		bean.setTimeLimitQuantity(timeLimitQuantity);
		bean.setTimeLimitUnit(timeLimitUnit);
		
		beanShopRecommendationCustomDao.save(bean);
		
		return bean;
	}

	@Override
	public void update(Long id, Long typeId, BigDecimal timeLimitQuantity,
			String timeLimitUnit, BigDecimal price, String unit, Long scoreLower, Integer goodNumber) {
		BeanShopRecommendationType type = beanShopRecommendationCustomDao.findById(typeId, BeanShopRecommendationType.class);
		
		BeanShopRecommendationCustom bean = beanShopRecommendationCustomDao.findById(id, BeanShopRecommendationCustom.class);
		bean.setType(type);
		bean.setGoodNumber(goodNumber);
		bean.setPrice(price);
		bean.setUnit(unit);
		bean.setScoreLower(scoreLower);
		bean.setTimeLimitQuantity(timeLimitQuantity);
		bean.setTimeLimitUnit(timeLimitUnit);

	}
	
	


	@Override
	public List<BeanShopRecommendationCustom> getAll() {
		List<BeanShopRecommendationCustom> beans = beanShopRecommendationCustomDao.findAll(BeanShopRecommendationCustom.class);
		
		return beans;
	}

	@Override
	public List<BeanShopRecommendationCustom> getByTypeId(Long typeId) {
		BeanShopRecommendationType type = beanShopRecommendationCustomDao.findById(typeId, BeanShopRecommendationType.class);
		return beanShopRecommendationCustomDao.findByProperty("type", type, BeanShopRecommendationCustom.class);
	}

}
